package model

import (
	"gitee.com/xuxinzhi2206/corehub/database/mysql"
	"gorm.io/gorm"
)

type Goods struct {
	gorm.Model
	GoodsId    int64  `gorm:"type:int(11);comment:商品id"`
	GoodsName  string `gorm:"type:varchar(100);comment:商品名称"`
	GoodsNum   int64  `gorm:"type:int(11);comment:商品数量"`
	GoodsPrice int64  `gorm:"type:int(11);comment:商品价格"`
	GoodsImage string `gorm:"type:varchar(100);comment:商品图片"`
}

func (g *Goods) GoodsCreate() error {
	return mysql.WithMysql(func(db *gorm.DB) error {
		return db.Create(g).Error
	})
}
func (g *Goods) GetGoods() ([]Goods, error) {
	var List []Goods
	return List, mysql.WithMysql(func(db *gorm.DB) error {
		return db.Find(&List).Error
	})
}
func (g *Goods) DeleteGoods() error {
	return mysql.WithMysql(func(db *gorm.DB) error {
		return db.Delete(g).Error
	})
}
func (g *Goods) UpdateGoods() error {
	return mysql.WithMysql(func(db *gorm.DB) error {
		return db.Where("goods_id = ?", g.GoodsId).Where("goods_num", g.GoodsNum).Updates(g).Error
	})
}
